<?php
/**
 * AdminModule represents admin module 
 * Admin module is a place where website administrator can manage users, templates, modules, etc.
 * @author hau.danh <queeenearning@gmail.com>
 */
class AdminModule extends CWebModule
{
	public $defaultController = 'default';
	
	public static $info = array(
		'name'=>'Admin',
		'description'=>'The admin module where administrator can manage site resource',
		'version'=>'1.0'
	);
	public function init()
	{
		parent::init();
		$this->setImport(array(
			'admin.models.*',
			'admin.components.*',
		));
		
		parent::init();
		Yii::app()->user->loginUrl = Yii::app()->createUrl('admin/default/login');
		Yii::app()->theme = 'admin';
		//Check if user is login
	}

	public function beforeControllerAction($controller, $action)
	{
		if(parent::beforeControllerAction($controller, $action))
		{
			$route=$controller->id.'/'.$action->id;
			
			$publicPages=array(
				'default/login',
				'default/error',
			);
			if(Yii::app()->user->isGuest && !in_array($route,$publicPages))
				Yii::app()->user->loginRequired();
			else
				return true;
		}
		return false;
	}
}
